#ifndef FILTERTEMPLATE_H
#define FILTERTEMPLATE_H

#include <QImage>
enum FilterType{LAPLACE_4, LAPLACE_8 };

class FilterTemplate
{
public:
    FilterTemplate(int rows = 1, int cols = 1);
    FilterTemplate(enum FilterType type);
    ~FilterTemplate();
    void apply(QImage &from, QImage &to);
    QImage apply(QImage &image);
    void medianFilter(QImage &from, QImage &to);
    QImage medianFilter(QImage &image);
    void medianFilter_Indexed8(QImage &from, QImage &to);
    void medianFilter_RGB32(QImage &from, QImage &to);
    QImage medianFilter_Indexed8(QImage &image);
    QImage medianFilter_RGB32(QImage &image);
    void apply_Indexed8(QImage &from, QImage &to);    
    void apply_RGB32(QImage &from, QImage &to);
    QImage apply_Indexed8(QImage &image);
    QImage apply_RGB32(QImage &image);
    int get(int row, int col) const {return m_data[row * m_cols + col];}
    void set(int row, int col, int value) {m_data[row * m_cols + col] = value;}
    void buildLaplaceFilter4();
    void buildLaplaceFilter8();
    void buildSmooth(int N);
    void buildGauss33();
    void build33();

public:
    int m_cols;
    int m_rows;
    int m_div;
    int m_xCenter;
    int m_yCenter;
    int * m_data;

    const uchar *m_image_data;
    int m_image_stride;
    int m_image_width;
    int m_image_height;
private:
    void allocMemory(int cols, int rows);
    uchar conv_Indexed8(int x, int y);
    QRgb conv_RGB32(int x, int y);
    uchar conv_Bound_Indexed8(int x, int y);

    uchar medianValue_Indexed8(int x, int y);
    QRgb medianValue_RGB32(int x, int y);

};

#endif // FILTERTEMPLATE_H
